package sequentiell;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Lukas Subel, Patrick Bender
 *
 */
public class Masche {
	
	/**
	 * The identifying ID of the masche.
	 */
	private int id;
	/**
	 * The list with all the nodes contained by the masche.
	 */
	private ArrayList<Node> masche;


	
	/**
	 * Give the list of all nodes contained by the masche.
	 * @return The list.
	 */
	public ArrayList<Node> getMasche() {
		return masche;
	}

	/**
	 * Set the list of all containing nodes to a existing one.
	 * @param masche The list.
	 */
	public void setMasche(ArrayList<Node> masche) {
		if (masche == null) throw new IllegalArgumentException("Masche can't be null");
		this.masche = masche;
	}

	/**
	 * The constructor of the masche.
	 * @param id The identifying number.
	 * @param masche The list of nodes the masche contains.
	 */
	public Masche(Integer id, ArrayList<Node> masche) {
		if (masche == null) throw new IllegalArgumentException("Masche can't be null");
		this.setId(id);
		this.masche = masche;
	}
	
	/**
	 * Default constructor;
	 * initialize a new empty list.
	 */
	public Masche() {
		this.masche = new ArrayList<Node>();
	}
	
	/**
	 * Another constructor; get the informations from another masche.
	 * @param masche The other masche.
	 */
	public Masche(Masche masche) {
		if (masche == null) throw new IllegalArgumentException("Masche can't be null");
		this.masche = new ArrayList<Node>(masche.masche);
		this.id = masche.id;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		String erg = "" + id + ":{";
		for(Node act : masche)
		{
			erg += act.getId() + ", ";
		}
		if (masche.size() == 0) erg += "  ";
		return erg.substring(0, erg.length()-2) + "}";
	}

	/**
	 * Add a node to the masche. Set the masche of the node.
	 * @param node The node to add. Checks if the argument is null.
	 */
	public void add(Node node) {
		if (node == null) throw new IllegalArgumentException("Node can't be null");
		this.masche.add(node);
		node.setMasche(this);
	}

	
	/**
	 * Check if the masche contains all nodes of an given collection of nodes.
	 * @param c the given collection.
	 * @return True if the masche contains all nodes.
	 */
	public boolean containsAll(Collection<?> c) {
	return this.masche.containsAll(c);
	}
	
	/**
	 * Set the ID of the masche.
	 * @param id The identifying number.
	 */
	public void setId(int id) {
		this.id = id;
	}

	
	/** 
	 * Get the ID of the masche.
	 * @return The identifying number.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Remove a node from the masche.
	 * @param act The node to remove.
	 * @return True, when the node was successfully removed.
	 */
	public boolean remove(Node act) {
		return this.masche.remove(act);
	}
	
}
